<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head lang="en">
		<meta charset="utf-8" />
		<title>最家</title>
		<link rel="stylesheet" type="text/css" href="<%=basePath%>frontPage/css/public.css"/>
		<link rel="stylesheet" type="text/css" href="<%=basePath%>frontPage/css/proList.css" />
		<link rel="stylesheet" type="text/css" href="<%=basePath%>frontPage/css/myorder.css" />
		<link rel="stylesheet" type="text/css" href="<%=basePath%>frontPage/css/mygxin.css" />
		<script type="text/javascript" src="<%=basePath%>frontPage/js/jquery-2.1.0.js"></script>
		
		<script type="text/javascript">
			function delAddress(id){
	    		if(confirm("确定要删除该地址吗？")){
	    			$.ajax({
	    				url:"<%=basePath%>delAddressById/"+id,
						type:"post",
						dataType:"text",
						success:function(data){	
							//刷新页面重新加载
							window.location.reload();
						},
						error:function(){
							
						}
	    			})
	    		}
	    	};
	    	
	    	//编辑时回显地址信息
	    	function updateAddress(id){
				$.ajax({
					url:"<%=basePath%>selectAddress/"+id,
					type:"post",
					dataType:"json",
					success:function(data){	
						$("#addressIdXX").val(data.id);
						$("#f_uid").val(data.f_uid);
						$("#addreName").val(data.name);
						$("#addrePhone").val(data.phone);
						$("#provinceId").val(data.province);
						$("#cityId").val(data.city);
						$("#areaId").val(data.area);
						$("#addressInfoId").val(data.addressInfo);
						$(".mask").show();
						$(".adddz").show();
					},
					error:function(){
						
					}
				})										
			};
	    	$(function(){						
			    //订单页面  修改地址
				$("#editAddressxx").click(function(){
					$.ajax({
						url:"<%=basePath%>editAddress",
						type:"post",
						dataType:"text",
						data:$("#editxx").serialize(),
						success:function(data){	
							window.location.reload();
						},
						error:function(){
							
						}
					})										
				});
			});	
	    	$(function(){								
			    //订单页面  添加地址
				$("#addAddress").click(function(){
					$.ajax({
						url:"<%=basePath%>addAddress",
						data:$("#addAddress1").serialize(),//{"data":params}
			 			datatype:"json",
			 			success:function(data){
			 				window.location.reload();
			 			},
			 			error:function(){
			 				alert("添加失败！！");
			 			}
					})										
				});
			});	
		</script>
	</head>
	<body>
		<!------------------------------head------------------------------>
		<jsp:include page="header1.jsp"></jsp:include>
		<!------------------------------idea------------------------------>
		<div class="address mt">
			<div class="wrapper clearfix">
				<a href="" class="fl">首页</a>
				<span>/</span>
				<a href="">个人中心</a>
				<span>/</span>
				<a href="" class="on">地址管理</a>
			</div>
		</div>
		
		<!------------------------------Bott------------------------------>
		<div class="Bott">
			<div class="wrapper clearfix">
				<div class="zuo fl">
					<h3>
						<a href="#"><img src="<%=basePath%>frontPage/img/tx.png"/></a>
						<p class="clearfix"><span class="fl">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${user.name }</span></p>
					</h3>
					<div>
						<h4>我的交易</h4>
						<ul>
							<li><a href="<%=basePath%>toShoppingCartPage/${userId}">我的购物车</a></li>
							<li><a href="<%=basePath%>findOrderInfo/${userId}/5">我的订单</a></li>
						</ul>
						<h4>个人中心</h4>
						<ul>
							<li class="on"><a href="<%=basePath%>findOrderInfo/${userId}/5">地址管理</a></li>
						</ul>
						<h4>账户管理</h4>
						<ul>
							<li><a href="<%=basePath%>tomymessagePage/${userId}">个人信息</a></li>
							<li><a href="<%=basePath%>changepassword/${userId}">修改密码</a></li>
						</ul>
					</div>
				</div>
				<div class="you fl">
					<h2>收货地址</h2>					
					<div class="order cart">						
						<!-----------------orderCon------------------->
						<div class="orderCon wrapper clearfix">
							<div class="orderL fl">
								<!--------h3---------------->
								<h3><a href="#" class="fr addAdre">新增地址</a></h3>
								<!--------address---------------->
								<div class="addres clearfix">
								    <c:forEach items="${address }" var="address">
									    <c:if test="${address.defaultAddress==1 }">								        				        
									        <div class="addre fl">
									            <input type="hidden" value="${address.id }" id="addressId">
												<div class="tit clearfix">
													<p class="fl">${address.name }
														<span class="default">[默认地址]</span>
													</p>
													<p class="fr">
														<a onclick="delAddress(${address.id})">删除</a>
														<span>|</span>
														<a onclick="updateAddress(${address.id})">编辑</a>
													</p>
												</div>
												<div class="addCon">
													<p>${address.province }&nbsp;${address.city }&nbsp;${address.area }&nbsp;${address.addressInfo }</p>
													<p>${address.phone }</p>
												</div>
										    </div>	
									    </c:if>
									    <c:if test="${address.defaultAddress==0 }">								        				        
									        <div class="addre fl">
									            <input type="hidden" value="${address.id }" id="addressId">
												<div class="tit clearfix">
													<p class="fl">${address.name }
														<span class="setDefault">设为默认</span>
													</p>
													<p class="fr">
														<a onclick="delAddress(${address.id})">删除</a>
														<span>|</span>
														<a onclick="updateAddress(${address.id})">编辑</a>
													</p>
												</div>
												<div class="addCon">
													<p>${address.province }&nbsp;${address.city }&nbsp;${address.area }&nbsp;${address.addressInfo }</p>
													<p>${address.phone }</p>
												</div>
										    </div>	
									    </c:if>			    	
								    </c:forEach>																												
								</div>																
							</div>						
						</div>
					</div>					
				</div>
			</div>
		</div>
		<!--编辑弹框-->
		<!--遮罩-->
		<div class="mask"></div>
		<div class="adddz">
			<form action="#" method="get" id="editxx">
				<input type="hidden" id="addressIdXX" id="id" name="id">
				<input type="hidden" id="f_uid" name="f_uid">
				<input type="text" placeholder="姓名" name="name" id="addreName" class="on" />
				<input type="text" id="addrePhone" name="phone" placeholder="手机号" />
				<div class="city">					
					<input type="text" name="province" id="provinceId">					
					<input type="text" name="city" id="cityId">
					
					<input type="text" id="areaId" name="area">
				</div>
				<textarea name="addressInfo" id="addressInfoId" rows="" cols="" placeholder="详细地址"></textarea>
				<div class="bc">
					<input type="button" value="保存" id="editAddressxx"/>
					<input type="button" value="取消" />
				</div>
			</form>
		</div>
		<div class="readd">
			<form action="#" method="get" id="addAddress1">
				<input type="hidden" name="f_uid" value="${userId }" />
				<input type="text"  class="on" name="name" value="六六六" />
				<input type="text" name="phone" value="157****0022" />
				<div class="city">
					<select name="province" id="province">
						
					</select>
					<select name="city" id="city">
						
					</select>
					<select name="area" id="area">
						
					</select>			
				</div>
				<textarea name="addressInfo" rows="" cols="" placeholder="详细地址">高新产业园</textarea>
				<div class="bc">
					<input type="button" value="保存" id="addAddress"/>
					<input type="button" value="取消" />
				</div>
			</form>
		</div>
		<!--返回顶部-->
		<jsp:include page="gotop.jsp"></jsp:include>
		
		
		<!--footer-->
		<jsp:include page="footer.jsp"/>
		<script src="<%=basePath%>frontPage/js/jquery-1.12.4.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="<%=basePath%>frontPage/js/public.js" type="text/javascript" charset="utf-8"></script>
		<script src="<%=basePath%>frontPage/js/user.js" type="text/javascript" charset="utf-8"></script>
	</body>
</html>
